package com.wgts.wgts.mvp.presenter.imp;

import com.wgts.wgts.mvp.model.IContinuePayActivityModel;
import com.wgts.wgts.mvp.model.IGetUserInfoModel;
import com.wgts.wgts.mvp.presenter.IContinuePayActivityPresenter;
import com.wgts.wgts.mvp.view.IContinuePayActivityView;
import com.wgts.wgts.netmodle.HttpResultSubscriber;
import com.wgts.wgts.netmodle.resp.OrderEntity;
import com.wgts.wgts.netmodle.resp.UserInfoEntity;
import com.wgts.wgts.tools.AppInfor;

/*
 *
 *
 *   data:2018/10/910:19
 *
 */public class ContinuePayActivityPresenter implements IContinuePayActivityPresenter {
     private IContinuePayActivityView view;
     private IContinuePayActivityModel model;
     private IGetUserInfoModel userInfoModel;

    public ContinuePayActivityPresenter(IContinuePayActivityView view, IContinuePayActivityModel model, IGetUserInfoModel userInfoModel) {
        this.view = view;
        this.model = model;
        this.userInfoModel = userInfoModel;
    }

    @Override
    public void userInfo() {
        if(AppInfor.getInstance().getRefreshToken().equals("")){
            view.userInfoResult(null);
            return;
        }

        userInfoModel.userInfo(new HttpResultSubscriber<UserInfoEntity>() {
            @Override
            public void onSuccess(UserInfoEntity userInfoEntity) {
                AppInfor.getInstance().setUserPhone(userInfoEntity.userPhone);
                AppInfor.getInstance().setUserState(userInfoEntity.userRole);
                AppInfor.getInstance().setAvailableBalance(userInfoEntity.availableBalance);
                view.userInfoResult(userInfoEntity);
            }

            @Override
            public void _onError(int status, String msg) {

            }
        });
    }

    @Override
    public void continuePay(String orderId, String payType, String payPassword) {
        model.continuePay(orderId, payType, payPassword, new HttpResultSubscriber<OrderEntity>() {
            @Override
            public void onSuccess(OrderEntity orderEntity) {
                view.continuePay(orderEntity);
            }

            @Override
            public void _onError(int status, String msg) {
                view.onError(status, msg);
            }
        });
    }
}
